import java.util.PriorityQueue;

public class Solution2279 {
    public int maximumBags(int[] capacity, int[] rocks, int additionalRocks) {
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<>();
        for (int i=0;i<capacity.length;i++){
            priorityQueue.offer(capacity[i]-rocks[i]);
        }
        int ans=0;
        while (!priorityQueue.isEmpty()){
            if (additionalRocks>=priorityQueue.peek()){
                ans++;
                additionalRocks-=priorityQueue.poll();
            }else {
                break;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution2279().maximumBags(new int[]{2,3,4,5},new int[]{1,2,4,4},2));
    }
}
